import java.util.ArrayList;
import java.util.Comparator;

public class ArrayListTest19 {
    public static void main(String[] args) {
        ArrayList<String> arrayList=new ArrayList<>();
        arrayList.add("北京");
        arrayList.add("上海");
        arrayList.add("山东省");
        arrayList.add("宁夏回族自治区");
        arrayList.add("内蒙古自治区");
        arrayList.sort(Comparator.comparing(String::length));
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.println(arrayList.get(i));
        }
    }
}
